﻿using System;
using Zinnia.Lite.Injection;
using Zinnia.Lite.Repository;
using Zinnia.Services.Models;

namespace Zinnia.Services.Business
{
    /// <summary>
    /// 用户模块接口
    /// </summary>
    public interface IUserService : IUnitOfWorkDependency
    {
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="user"></param>
        void UserRegister(User user);
    }

    public class UserService : IUserService
    {
        private readonly IRepository<User> _useRepository;

        public UserService(IRepository<User> useRepository)
        {
            _useRepository = useRepository;
        }

        public void UserRegister(User user)
        {
            try
            {
                _useRepository.Add(user);
                _useRepository.Context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
